import request from "@/modules/index/utils/request";
import qs from "qs";

const store = {
    state: {
        introduction: ""
    },
    mutations: {
        SET_CODE: (state, code) => {
            state.code = state.code + code;
        },
        SET_INTRODUCTION: (state, introduction) => {
            state.introduction = introduction;
        }
    },
    actions: {
        /**
         * 特征画布字段列表
         * */
        // 列表
        async feCanvasList(context) {
            const data = await request({
                url: "feCanvas/list",
                method: "get"
            });
            return data;
        },
        // 列表By Id
        async feCanvasListById(context, params) {
            const data = await request({
                url: `feCanvas/getById?${params}`,
                method: "get"
            });
            return data;
        },
        // 分页列表
        async feCanvasPageList(context, params) {
            const data = await request({
                url: params
                    ? `feCanvas/pageList?${params}`
                    : "feCanvas/pageList",
                method: "get"
            });
            return data;
        },
        // 新增
        async feCanvasSave(context, params) {
            const data = await request({
                url: "feCanvas/save",
                method: "post",
                data: params
            });
            return data;
        },
        // 修改或新增
        async feCanvasSaveOrUpdate(context, params) {
            const data = await request({
                url: "feCanvas/saveOrUpdate",
                method: "post",
                data: params
            });
            return data;
        },
        async feCanvasSaveOrUpdateBatch(context, params) {
            const data = await request({
                url: "feCanvas/saveOrUpdateBatch",
                method: "post",
                data: params
            });
            return data;
        },
        // 删除
        async feCanvasBatchDelete(context, params) {
            const data = await request({
                url: "feCanvas/deleteByIds",
                method: "post",
                params: params,
                paramsSerializer: params => {
                    return qs.stringify(params, { indices: false });
                }
            });
            return data;
        },

        /**
         * 特征画布算子线段
         * */
        // 列表
        async feLineList(context, params) {
            const data = await request({
                url: params ? `feLine/list?${params}` : "feLine/list",
                method: "get"
            });
            return data;
        },
        // 列表By Id
        async feLineListById(context, params) {
            const data = await request({
                url: `feLine/getById?id=${params}`,
                method: "get"
            });
            return data;
        },
        // 分页列表
        async feLinePageList(context, params) {
            const data = await request({
                // url: 'feLine/pageList',
                url: params ? `feLine/pageList?${params}` : "feLine/pageList",
                method: "get"
            });
            return data;
        },
        // 新增
        async feLineSave(context, params) {
            const data = await request({
                url: "feLine/save",
                method: "post",
                feLine: params
            });
            return data;
        },
        // 修改或新增
        async feLineSaveOrUpdate(context, params) {
            const data = await request({
                url: "feLine/saveOrUpdate",
                method: "post",
                data: params
            });
            return data;
        },
        async feLineSaveOrUpdateBatch(context, params) {
            const data = await request({
                url: "feLine/saveOrUpdateBatch",
                method: "post",
                data: params
            });
            return data;
        },
        // 删除
        async feLineBatchDelete(context, params) {
            const data = await request({
                url: "feLine/deleteByIds",
                method: "post",
                params: params,
                paramsSerializer: params => {
                    return qs.stringify(params, { indices: false });
                }
            });
            return data;
        },

        /**
         * 特征画布算子
         * */
        // 列表
        async feOperatorList(context, params) {
            const data = await request({
                url: params ? `feOperator/list?${params}` : "feOperator/list",
                method: "get"
            });
            return data;
        },
        // 列表By Id
        async feOperatorListById(context, params) {
            const data = await request({
                url: `feOperator/getById?id=${params}`,
                method: "get"
            });
            return data;
        },
        // 分页列表
        async feOperatorPageList(context, params) {
            const data = await request({
                // url: 'feCanvas/pageList',
                url: params
                    ? `feOperator/pageList?${params}`
                    : "feOperator/pageList",
                method: "get"
            });
            return data;
        },
        // 新增
        async feOperatorSave(context, params) {
            const data = await request({
                url: "feOperator/save",
                method: "post",
                data: params
            });
            return data;
        },
        // 修改或新增
        async feOperatorSaveOrUpdate(context, params) {
            const data = await request({
                url: "feOperator/saveOrUpdate",
                method: "post",
                data: params
            });
            return data;
        },
        async feOperatorSaveOrUpdateBatch(context, params) {
            const data = await request({
                url: "feOperator/saveOrUpdateBatch",
                method: "post",
                data: params
            });
            return data;
        },
        // 删除
        async feOperatorBatchDelete(context, params) {
            const data = await request({
                url: "feOperator/deleteByIds",
                method: "post",
                params: params,
                paramsSerializer: params => {
                    return qs.stringify(params, { indices: false });
                }
            });
            return data;
        },
        // 获取画布的所有节点信息(用作回显)
        async getCanvasRenderData(context, params) {
            const data = await request({
                url: `/feCanvas/list?id=${params}`,
                method: "get"
            });
            return data;
        },
    }
};

export default store;
